import Vue from 'vue'
import Vuex from 'vuex'

var cm = require("../components/common.js");

Vue.use(Vuex)

const state = {
    isShowAddStaff: false, //  是否添加营业员弹框
    headerTitle:"",
    userName:"",
    errorMsg:"",
    loginName:"112233443343434",   // 商户号 或手机号
    mer_id:"999497048140002",  //商户号
    loginType:"1",    //登录角色
    showLoading:false,
    staffs:[],
    token:"z19V3mwDwF bu6zVNz5589HHeDgJsLJ fdOjANlzssK7qZipl9u5gaX7/Yoz996QPHzrsl6OKEjem5I0yfwItzYB/JaottjZ",
    openid:"oPBvwwmOuuEUCkvRHWxzU61uOD0U",
    prdtNo:"0301",
    /***********订单详情******************/
    transSeq:"",                   // 取订单详情参数
    detailItem:"",
    /************************当前时间************/
    nowDate:"",
    /***************营业员信息弹框用的************************/
    fillInfo:false,
    setFillInfo:false,
    /***********************************************/
    contactPhone:"",     // 登入商户手机号
}

const mutations = {
    getUserName(){
        state.userName = "测试用户"
    },

    getSelectionInfo(){
        state.token = sessionStorage.getItem("tltd_token");
        state.loginName = sessionStorage.getItem("tltd_loginName");
        state.openid = sessionStorage.getItem("tltd_openid");
        state.loginType = sessionStorage.getItem("tltd_loginType");
    },
    getprdtNo(){
        var parameter = {
            token:state.token,
            loginName:state.loginName,
            bizLicNo:state.loginName,
            openid:state.openid,
            loginType:1
        };

        $.post(MerExtraSearch_URL,parameter,function(pdata) {
            if(pdata.lfq_merextrainfo_response && pdata.lfq_merextrainfo_response.prdt_no){
                state.prdtNo = pdata.lfq_merextrainfo_response.prdt_no;
                state.contactPhone = pdata.lfq_merextrainfo_response.contact_phone;
            }else{
                state.errorMsg = "取商户产品号失败";
            }
        });
    },
    setNowDate(state,dateStr){
        state.nowDate = new Date();
        $.post(XtsdOrderServlet,{"servlet_type":"query_today"},function(dmsg) {
            if(dmsg.today_response && dmsg.today_response.today){
                var nowDateStr = cm.getDateStrFormate1(dmsg.today_response.today,"date") + " 23:59:59";
                state.nowDate = new Date(nowDateStr);
            }
        });
    }
}

export default new Vuex.Store({
    state,
    mutations
})
